<template>
	<view class="">

		<!-- 顶部 -->
		<view class="top" style="display: flex;align-items: center;justify-content: flex-start;">
			<view class="topText"
				style="display: flex;padding-top: 50px;font-weight: bold;margin-left: 15px;font-size: 17px;">
				<p>消息</p>
				<u-icon style="margin-left: 8px;" size="40" name="eye-off"></u-icon>
			</view>

		</view>
		<!-- 搜索 -->
		<view class="sousuo" style="margin-top: 20px;padding: 0 10px;">
			<u-search placeholder="日照香炉生紫烟" v-model="keyword" animation="false" bgColor="white" height="80"
				class="searchBox" style="paddto" shape="round"></u-search>
		</view>

		<view class="newsCard">
			<!-- 消息列表 -->
			<newCard :newItem="notifyItem"></newCard>
			<newCard :newItem="interactionItem"></newCard>
			<newCard :newItem="selectedItem"></newCard>


			<view class="" v-for="(item,index) in newsList" @click="gotoChat(item)">
				<newCard :newItem="item"></newCard>
			</view>

		</view>

	</view>
</template>

<script>
	import newCard from './components/newCard.vue'
	export default {
		data() {
			return {
				newsList: [],
				notifyItem: {
					userPic: 'https://img1.baidu.com/it/u=1110918159,756279650&fm=253&fmt=auto&app=138&f=JPEG?w=500&h=500',
					nickName: '通知消息',
					content: 'sadsda',
					createTime: '2023-12-27'
				},
				interactionItem: {
					userPic: 'https://img1.baidu.com/it/u=189553567,3967936768&fm=253&fmt=auto&app=138&f=JPEG?w=500&h=500',
					nickName: '互动消息',
					content: '的计算框架设计',
					createTime: '2023-12-27'
				},
				selectedItem: {
					userPic: 'https://img1.baidu.com/it/u=1224260625,2422628894&fm=253&fmt=auto&app=138&f=JPEG?w=500&h=500',
					nickName: '精选消息',
					content: '搜索vv',
					createTime: '2023-12-27'
				}
			}
		},
		components: {
			newCard
		},
		methods: {
			gotoChat(skuInfo) {
				console.log(skuInfo);
				// 将 skuInfo 对象转换为字符串，并使用 encodeURIComponent 方法进行 URL 编码
				const skuInfoStr = encodeURIComponent(JSON.stringify(skuInfo));

				// 拼接 URL，将 skuInfo 的字符串形式作为参数传递
				const url = '../../pagesA/chat/chat?userId=' + skuInfo.friendId + '&skuInfo=' + skuInfoStr;
				uni.navigateTo({
					url: url
				});
			}
		},
		mounted: async function() {
			let result = await this.$u.api.findNewsList()
			console.log(result);
			this.newsList = result.records
		}
	}
</script>

<style lang="scss">

</style>